package com.gitee.hljdrl.lite.privacy;

import android.content.Context;


import com.gitee.hljdrl.lite.Lite;

import java.io.File;
import java.io.IOException;

public class PrivacyUtil implements PrivacyEvent {

    /**
     * 是否同意服务条款：true=已同意,false=未同意
     */
    public static boolean isAccept(Context context) {
        boolean result = false;
        final File cacheFile = context.getCacheDir();
        final File acceptFile = new File(cacheFile, KEY_ACCEPT);
        if (acceptFile.exists()) {
            result = true;
        }
        return result;
    }

    /**
     * 同意：服务条款
     */
    public static void accept(Context context) {
        final File cacheFile = context.getCacheDir();
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                File acceptFile = new File(cacheFile, KEY_ACCEPT);
                if (!acceptFile.exists()) {
                    try {
                        acceptFile.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        if (Lite.task != null) {
            Lite.task.post(runnable);
        } else {
            new Thread(runnable).start();
        }
    }
}
